package com.xxkfz.controller;

import cn.hutool.core.thread.ThreadUtil;
import com.xxkfz.aspect.rate.RateLimiter;
import com.xxkfz.enums.LimitType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: xxkfz-admin-redisson
 * @ClassName RateLimiterController.java
 * @author: 公众号：小小开发者
 * @create: 2024-01-21 16:29
 * @description: Redisson应用：自定义注解实现接口的限流功能
 * @Version 1.0
 **/
@RestController
@RequestMapping("rate")
@Slf4j
public class RateLimiterController {

    /**
     * 限流测试
     *
     * @param param1
     * @param param2
     */
    @GetMapping("rateTest")
    @RateLimiter(rateKey = "'xxkfz'+ #param1+#param2", count = 5, time = 10, limitType = LimitType.DEFAULT, errMsg = "访问超过限制,请稍后再试!")
    public void rateTest(String param1, String param2) {
        log.error("开始处理业务......");
        ThreadUtil.sleep(2000);
        log.error("处理业务完成......");
    }

}